const std = @import("std");

pub fn build(b: *std.Build) void {
    const target = b.standardTargetOptions(.{});
    const optimize = b.standardOptimizeOption(.{});

    // 创建静态库
    const lib = b.addStaticLibrary(.{
        .name = "asterinas_mm_zig",
        .root_source_file = .{ .path = "src/lib.zig" },
        .target = target,
        .optimize = optimize,
    });

    // 设置为裸机目标
    lib.setLibCFile(.{ .path = "libc.conf" });
    
    // 添加编译选项
    lib.addCSourceFile(.{
        .file = .{ .path = "src/c_bindings.c" },
        .flags = &[_][]const u8{
            "-std=c11",
            "-fno-stack-protector",
            "-nostdlib",
            "-ffreestanding",
        },
    });

    b.installArtifact(lib);

    // 创建测试
    const main_tests = b.addTest(.{
        .root_source_file = .{ .path = "src/lib.zig" },
        .target = target,
        .optimize = optimize,
    });

    const run_main_tests = b.addRunArtifact(main_tests);
    const test_step = b.step("test", "Run library tests");
    test_step.dependOn(&run_main_tests.step);
}